appCtrl.controller('LoginCtrl', function($scope, $rootScope, $state, $http, UtilsService, UserService) {
  $scope.login = function() {
    console.log(this.phone);
    UserService.login({
      phone: this.phone,
      pwd: this.pwd
    }).$promise.then(function(response) {
      if (UtilsService.isResponseOk(response)) {
        UtilsService.setToken(response.data.user.token);
        UtilsService.setUser(response.data.user);

        if (!$rootScope.dist) {
          $state.transitionTo('district.list');
        } else {
          $state.transitionTo('dash.home', {
            update: true
          }, {
            reload: true
          });
        }
      }
    })
  }


  $scope.goBack = function() {
    UtilsService.goBack();
  }
});
